package org.custom.spring.boot.transaction.controller.transactional;

import org.custom.spring.boot.transaction.service.transactional.TransactionalWithoutService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 无事务方法调用网络接口
 *
 * @author LiKun
 * @date 2021/9/17 10:13
 */
@RestController
@RequestMapping("/transaction/without")
public class TransactionalWithoutController {
    @Resource
    private TransactionalWithoutService transactionalWithoutService;

    @GetMapping("/{data1}/exception/{data2}")
    public int callTransactionException(@PathVariable("data1") String data1, @PathVariable("data2") String data2) {
        return transactionalWithoutService.callTransactionException(data1, data2);
    }

    @GetMapping("/exception/{data1}/{data2}")
    public int callExceptionTransaction(@PathVariable("data1") String data1, @PathVariable("data2") String data2) {
        return transactionalWithoutService.callExceptionTransaction(data1, data2);
    }

    @GetMapping("/new/{data1}/{data2}")
    public int newTransactionException(@PathVariable("data1") String data1, @PathVariable("data2") String data2) {
        return transactionalWithoutService.newTransactionException(data1, data2);
    }

    @GetMapping("/async/{data1}/{data2}")
    public int asyncCallTransactionException(@PathVariable("data1") String data1, @PathVariable("data2") String data2) throws Exception {
        return transactionalWithoutService.asyncCallTransactionException(data1, data2);
    }
}
